package com.dykj.fireFighting.server.monitoringCenter.service.impl;

import com.dykj.fireFighting.api.monitoringCenter.entity.*;
import com.dykj.fireFighting.api.monitoringCenter.service.IPgRegionRecordService;
import com.dykj.fireFighting.api.monitoringCenter.vo.PgRegionRecordScoreVo;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.utils.UUIDUtils;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.server.monitoringCenter.mapper.PgRegionMapper;
import com.dykj.fireFighting.server.monitoringCenter.mapper.PgRegionRecordMapper;
import com.dykj.fireFighting.server.monitoringCenter.mapper.PgRegionRecordScoreMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author JacksonTu
 * @Date 2022-02-16 10:17:27
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class PgRegionRecordServiceImpl extends BaseServiceImpl<PgRegionRecordMapper, PgRegionRecord> implements IPgRegionRecordService {

    @Autowired
    private PgRegionRecordScoreMapper regionRecordScoreMapper;
    @Autowired
    private PgRegionMapper regionMapper;

    /*private String[] nameList=new String[]{"易燃易爆化学品","加油/加气站密度\n","高层建筑\n","地下铁路\n","城乡结合部外来人口聚集区\n",
            "地下空间\n","电气火灾\n","用火不慎\n","放火致灾\n","吸烟不慎\n","建筑密度\n","人口密度\n","经济密度\n","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};*/
    @Override
    public int importScore(Map<String, Object> params) {
        LoginUserVo user = (LoginUserVo) params.get("user");
        String regionRecordId = (String) params.get("regionRecordId");
        List<PgScoreImport> scoreList = (List<PgScoreImport>) params.get("scoreList");
        List<PgQuanzhong> qz1 = (List<PgQuanzhong>) params.get("qz1");
        List<PgQuanzhong> qz2 = (List<PgQuanzhong>) params.get("qz2");
        List<PgRegionRecordScore> regionRecordScoreList = new ArrayList<>();
        for (int i = 0; i < scoreList.size(); i++) {
            PgRegionRecordScore regionRecordScore = new PgRegionRecordScore();
            double score = getFz(scoreList.get(i));
            regionRecordScore.setCreateBy(user.getId().toString());
            regionRecordScore.setCreateTime(new Date());
            regionRecordScore.setLevel(2);
            regionRecordScore.setName(scoreList.get(i).getName());
            regionRecordScore.setScore(score);
            regionRecordScore.setQz(Double.parseDouble(scoreList.get(i).getQz()));
            regionRecordScore.setId(UUIDUtils.get32UUID());
            BigDecimal b1 = new BigDecimal(scoreList.get(i).getQz());
            BigDecimal b2 = new BigDecimal(Double.toString(score));
            double gxz = b1.multiply(b2).doubleValue();
            regionRecordScore.setGxz(doubleZh(gxz));
            regionRecordScore.setRecordId(regionRecordId);
            regionRecordScoreList.add(regionRecordScore);
        }
        //regionRecordScoreList = getAll(regionRecordScoreList, user, regionRecordId, qz1, qz2);
        //int count = regionRecordScoreMapper.batchAdd(regionRecordScoreList);
        regionRecordScoreList=getAll(regionRecordScoreList,user,regionRecordId,qz1,qz2);

        for (int j = 0; j < regionRecordScoreList.size(); j++) {
            String fxdj="";
            double R=regionRecordScoreList.get(j).getScore();
            if(R>85){
                fxdj="低风险";
            }else if(R>65 && R<=85){
                fxdj="中风险";
            }else if(R>25 && R<=65){
                fxdj="高风险";
            }else if(R>0 && R<=25){
                fxdj="极高风险";
            }
            regionRecordScoreList.get(j).setFxdj(fxdj);
        }


        int count=regionRecordScoreMapper.batchAdd(regionRecordScoreList);

        double R = 0.0;
        for (int j = 0; j < regionRecordScoreList.size(); j++) {
            if (regionRecordScoreList.get(j).getLevel() == 0) {
                BigDecimal b1 = new BigDecimal(Double.toString(regionRecordScoreList.get(j).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(R));
                R = b1.add(b2).doubleValue();
            }
        }
        PgRegionRecord regionRecord = new PgRegionRecord();
        regionRecord.setId(regionRecordId);
        regionRecord.setScore(R);
        this.baseMapper.updateById(regionRecord);
        regionRecord = this.baseMapper.selectById(regionRecordId);
        PgRegion region = new PgRegion();
        region.setId(regionRecord.getRegionId());
        region.setPgzs(regionRecord.getPgzs());
        region.setScore(R);
        int fxdj=1;
        if(R>85){
            fxdj=1;
        }else if(R>65 && R<=85){
            fxdj=2;
        }else if(R>25 && R<=65){
            fxdj=3;
        }else if(R>0 && R<=25){
            fxdj=4;
        }
        region.setFxdj(fxdj);
        regionMapper.updateById(region);
        return count;
    }

    @Override
    public List<PgRegionRecordScoreVo> getPgRegionRecordScoreList(String regionId) {
        return regionRecordScoreMapper.getPgRegionRecordScoreList(regionId);
    }

    @Override
    public List<PgRegionRecordScoreVo> getpgRegionRecordScoreVoNumList(String regionId) {
        return regionRecordScoreMapper.getpgRegionRecordScoreVoNumList(regionId);
    }

    @Override
    public PgRegionRecord selectByRegionId(Map<String, Object> map) {
        return this.baseMapper.selectByRegionId(map);
    }

    public static List<PgRegionRecordScore> getAll(List<PgRegionRecordScore> list,LoginUserVo user,String regionRecordId,List<PgQuanzhong> qz1,List<PgQuanzhong> qz2){
        PgRegionRecordScore regionRecordScore0=new PgRegionRecordScore(UUIDUtils.get32UUID(),user.getId().toString(),new Date(),"-1",0,"火灾危险源",qz1.get(0).getQz(),null,null,regionRecordId);
        PgRegionRecordScore regionRecordScore1=new PgRegionRecordScore(UUIDUtils.get32UUID(),user.getId().toString(),new Date(),"-1",0,"城市基础信息",qz1.get(1).getQz(),null,null,regionRecordId);
        PgRegionRecordScore regionRecordScore2=new PgRegionRecordScore(UUIDUtils.get32UUID(),user.getId().toString(),new Date(),"-1",0,"消防力量",qz1.get(2).getQz(),null,null,regionRecordId);
        PgRegionRecordScore regionRecordScore3=new PgRegionRecordScore(UUIDUtils.get32UUID(),user.getId().toString(),new Date(),"-1",0,"火灾预警",qz1.get(3).getQz(),null,null,regionRecordId);
        PgRegionRecordScore regionRecordScore4=new PgRegionRecordScore(UUIDUtils.get32UUID(),user.getId().toString(),new Date(),"-1",0,"社会面防控能力",qz1.get(4).getQz(),null,null,regionRecordId);

        PgRegionRecordScore regionRecordScore5 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore0.getId(), 1, "重大危险因素", qz2.get(0).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore6 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore0.getId(), 1, "人为因素历史数据", qz2.get(1).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore7 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore1.getId(), 1, "城市基础信息", qz2.get(2).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore8 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore2.getId(), 1, "城市公共消防基础设施", qz2.get(3).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore9 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore2.getId(), 1, "灭火救援能力", qz2.get(4).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore10 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore3.getId(), 1, "火灾防控水平", qz2.get(5).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore11 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore3.getId(), 1, "火灾预警能力", qz2.get(6).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore12 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore3.getId(), 1, "公众消防安全感", qz2.get(7).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore13 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore4.getId(), 1, "消防管理", qz2.get(8).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore14 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore4.getId(), 1, "消防宣传教育", qz2.get(9).getQz(), null, null, regionRecordId);
        PgRegionRecordScore regionRecordScore15 = new PgRegionRecordScore(UUIDUtils.get32UUID(), user.getId().toString(), new Date(), regionRecordScore4.getId(), 1, "保障协作", qz2.get(10).getQz(), null, null, regionRecordId);
        List<PgRegionRecordScore> twoList = new ArrayList<>();
        double gxz = 0.0;
        for (int i = 0; i < list.size(); i++) {
            if (i <= 5) {
                list.get(i).setParentId(regionRecordScore5.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 5) {
                    regionRecordScore5.setScore(gxz);
                    BigDecimal b3 = new BigDecimal(regionRecordScore5.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore5.setGxz(doubleZh(gxz));

                    twoList.add(regionRecordScore5);
                    gxz = 0.0;
                }
            } else if (i > 5 && i <= 9) {
                list.get(i).setParentId(regionRecordScore6.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 9) {
                    regionRecordScore6.setScore(gxz);
                    //regionRecordScore6.setGxz(doubleZh(gxz*regionRecordScore6.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore6.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore6.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore6);
                    gxz = 0.0;
                }
            } else if (i > 9 && i <= 15) {
                list.get(i).setParentId(regionRecordScore7.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 15) {
                    regionRecordScore7.setScore(gxz);
                    //regionRecordScore7.setGxz(doubleZh(gxz*regionRecordScore7.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore7.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore7.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore7);
                    gxz = 0.0;
                }
            } else if (i > 15 && i <= 19) {
                list.get(i).setParentId(regionRecordScore8.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 19) {
                    regionRecordScore8.setScore(gxz);
                    //regionRecordScore8.setGxz(doubleZh(gxz*regionRecordScore8.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore8.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore8.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore8);
                    gxz = 0.0;
                }
            } else if (i > 19 && i <= 23) {
                list.get(i).setParentId(regionRecordScore9.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 23) {
                    regionRecordScore9.setScore(gxz);
                    //regionRecordScore9.setGxz(doubleZh(gxz*regionRecordScore9.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore9.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore9.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore9);
                    gxz = 0.0;
                }
            } else if (i > 23 && i <= 26) {
                list.get(i).setParentId(regionRecordScore10.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 26) {
                    regionRecordScore10.setScore(gxz);
                    //regionRecordScore10.setGxz(doubleZh(gxz*regionRecordScore10.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore10.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore10.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore10);
                    gxz = 0.0;
                }
            } else if (i > 26 && i <= 28) {
                list.get(i).setParentId(regionRecordScore11.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 28) {
                    regionRecordScore11.setScore(gxz);
                    //regionRecordScore11.setGxz(doubleZh(gxz*regionRecordScore11.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore11.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore11.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore11);
                    gxz = 0.0;
                }
            } else if (i > 28 && i <= 29) {
                list.get(i).setParentId(regionRecordScore12.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 29) {
                    regionRecordScore12.setScore(gxz);
                    //regionRecordScore12.setGxz(doubleZh(gxz*regionRecordScore12.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore12.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore12.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore12);
                    gxz = 0.0;
                }
            } else if (i > 29 && i <= 32) {
                list.get(i).setParentId(regionRecordScore13.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 32) {
                    regionRecordScore13.setScore(gxz);
                    //regionRecordScore13.setGxz(doubleZh(gxz*regionRecordScore13.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore13.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore13.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore13);
                    gxz = 0.0;
                }
            } else if (i > 32 && i <= 35) {
                list.get(i).setParentId(regionRecordScore14.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 35) {
                    regionRecordScore14.setScore(gxz);
                    //regionRecordScore14.setGxz(doubleZh(gxz*regionRecordScore14.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore14.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore14.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore14);
                    gxz = 0.0;
                }
            } else if (i > 35 && i <= 38) {
                list.get(i).setParentId(regionRecordScore15.getId());
                BigDecimal b1 = new BigDecimal(Double.toString(list.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz));
                gxz = b1.add(b2).doubleValue();
                if (i == 38) {
                    regionRecordScore15.setScore(gxz);
                    //regionRecordScore15.setGxz(doubleZh(gxz*regionRecordScore15.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore15.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz));
                    gxz = b3.multiply(b4).doubleValue();
                    regionRecordScore15.setGxz(doubleZh(gxz));
                    twoList.add(regionRecordScore15);
                    gxz = 0.0;
                }
            }
        }

        double gxz1 = 0.00;
        for (int i = 0; i < twoList.size(); i++) {
            if (i <= 1) {
                BigDecimal b1 = new BigDecimal(Double.toString(twoList.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz1));
                gxz1 = b1.add(b2).doubleValue();
                //gxz1+=twoList.get(i).getGxz();
                if (i == 1) {
                    regionRecordScore0.setScore(gxz1);
                    //regionRecordScore0.setGxz(doubleZh(gxz1*regionRecordScore0.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore0.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz1));
                    gxz1 = b3.multiply(b4).doubleValue();
                    regionRecordScore0.setGxz(doubleZh(gxz1));
                    gxz1 = 0.0;
                }
            } else if (i > 1 && i <= 2) {
                BigDecimal b1 = new BigDecimal(Double.toString(twoList.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz1));
                gxz1 = b1.add(b2).doubleValue();
                if (i == 2) {
                    regionRecordScore1.setScore(gxz1);
                    //regionRecordScore1.setGxz(doubleZh(gxz1*regionRecordScore1.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore1.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz1));
                    gxz1 = b3.multiply(b4).doubleValue();
                    regionRecordScore1.setGxz(doubleZh(gxz1));
                    gxz1 = 0.0;
                }
            } else if (i > 2 && i <= 4) {
                BigDecimal b1 = new BigDecimal(Double.toString(twoList.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz1));
                gxz1 = b1.add(b2).doubleValue();
                if (i == 4) {
                    regionRecordScore2.setScore(gxz1);
                    //regionRecordScore2.setGxz(doubleZh(gxz1*regionRecordScore2.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore2.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz1));
                    gxz1 = b3.multiply(b4).doubleValue();
                    regionRecordScore2.setGxz(doubleZh(gxz1));
                    gxz1 = 0.0;
                }
            } else if (i > 4 && i <= 7) {
                BigDecimal b1 = new BigDecimal(Double.toString(twoList.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz1));
                gxz1 = b1.add(b2).doubleValue();
                if (i == 7) {
                    regionRecordScore3.setScore(gxz1);
                    //regionRecordScore3.setGxz(doubleZh(gxz1*regionRecordScore3.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore3.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz1));
                    gxz1 = b3.multiply(b4).doubleValue();
                    regionRecordScore3.setGxz(doubleZh(gxz1));
                    gxz1 = 0.0;
                }
            } else if (i > 7 && i <= 10) {
                BigDecimal b1 = new BigDecimal(Double.toString(twoList.get(i).getGxz()));
                BigDecimal b2 = new BigDecimal(Double.toString(gxz1));
                gxz1 = b1.add(b2).doubleValue();
                if (i == 10) {
                    regionRecordScore4.setScore(gxz1);
                    //regionRecordScore4.setGxz(doubleZh(gxz1*regionRecordScore4.getQz()));
                    BigDecimal b3 = new BigDecimal(regionRecordScore4.getQz());
                    BigDecimal b4 = new BigDecimal(Double.toString(gxz1));
                    gxz1 = b3.multiply(b4).doubleValue();
                    regionRecordScore4.setGxz(doubleZh(gxz1));
                    gxz1 = 0.0;
                }
            }
        }
        list.add(regionRecordScore0);
        list.add(regionRecordScore1);
        list.add(regionRecordScore2);
        list.add(regionRecordScore3);
        list.add(regionRecordScore4);
        list.add(regionRecordScore5);
        list.add(regionRecordScore6);
        list.add(regionRecordScore7);
        list.add(regionRecordScore8);
        list.add(regionRecordScore9);
        list.add(regionRecordScore10);
        list.add(regionRecordScore11);
        list.add(regionRecordScore12);
        list.add(regionRecordScore13);
        list.add(regionRecordScore14);
        list.add(regionRecordScore15);
        return list;
    }

    public static double getFz(PgScoreImport scoreImport) {
        List<int[]> abList = new ArrayList<>();
        if (StringUtils.isNotBlank(scoreImport.getZj1xx()) && StringUtils.isNotBlank(scoreImport.getZj1sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj1xx()), Integer.parseInt(scoreImport.getZj1sx())});
        }
        if (StringUtils.isNotBlank(scoreImport.getZj2xx()) && StringUtils.isNotBlank(scoreImport.getZj2sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj2xx()), Integer.parseInt(scoreImport.getZj2sx())});
        }
        if (StringUtils.isNotBlank(scoreImport.getZj3xx()) && StringUtils.isNotBlank(scoreImport.getZj3sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj3xx()), Integer.parseInt(scoreImport.getZj3sx())});
        }
        if (StringUtils.isNotBlank(scoreImport.getZj4xx()) && StringUtils.isNotBlank(scoreImport.getZj4sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj4xx()), Integer.parseInt(scoreImport.getZj4sx())});
        }
        if (StringUtils.isNotBlank(scoreImport.getZj5xx()) && StringUtils.isNotBlank(scoreImport.getZj5sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj5xx()), Integer.parseInt(scoreImport.getZj5sx())});
        }
        if (StringUtils.isNotBlank(scoreImport.getZj6xx()) && StringUtils.isNotBlank(scoreImport.getZj6sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj6xx()), Integer.parseInt(scoreImport.getZj6sx())});
        }
        if (StringUtils.isNotBlank(scoreImport.getZj7xx()) && StringUtils.isNotBlank(scoreImport.getZj7sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj7xx()), Integer.parseInt(scoreImport.getZj7sx())});
        }
        if (StringUtils.isNotBlank(scoreImport.getZj8xx()) && StringUtils.isNotBlank(scoreImport.getZj8sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj8xx()), Integer.parseInt(scoreImport.getZj8sx())});
        }
        if (StringUtils.isNotBlank(scoreImport.getZj9xx()) && StringUtils.isNotBlank(scoreImport.getZj9sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj9xx()), Integer.parseInt(scoreImport.getZj9sx())});
        }
        if (StringUtils.isNotBlank(scoreImport.getZj10xx()) && StringUtils.isNotBlank(scoreImport.getZj10sx())) {
            abList.add(new int[]{Integer.parseInt(scoreImport.getZj10xx()), Integer.parseInt(scoreImport.getZj10sx())});
        }
        double d1 = 0;
        double d2 = 0;
        for (int[] ab : abList) {
            d1 += Math.pow(ab[1], 2) - Math.pow(ab[0], 2);
            d2 += ab[1] - ab[0];
        }
        System.out.println(0.5 * d1 / d2);
        double a = 0.5 * d1 / d2;
        BigDecimal b0 = new BigDecimal(Double.toString(a));
        return b0.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public static double doubleZh(double a) {
        BigDecimal b0 = new BigDecimal(Double.toString(a));
        return b0.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public static double add(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.add(b2).doubleValue();
    }

    public static void main(String[] args) {
        double a = 25.95;
        BigDecimal b5 = new BigDecimal("25.95");
        System.out.println(b5);
        System.out.println(b5.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
    }
}
